package com.htu.edu.controller;

import com.htu.edu.bean.*;
import com.htu.edu.common.R;
import com.htu.edu.mapper.BusinessMapper;
import com.htu.edu.mapper.OrdersMapper;
import com.htu.edu.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
// 2. 设置该模块的请求路径，如/user
@RequestMapping("/Orders")
// 3. 解决跨域
@CrossOrigin
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private OrdersMapper ordersMapper;
    @Autowired
    private BusinessMapper businessMapper;

    @PostMapping("/createOrders")
    public R createOrders(Orders orders){
        try {
            int orders1 = ordersService.createOrders(orders);
            return R.ok().data(orders1);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @PostMapping("/getOrdersById")
    public R getOrdersById(Integer orderId){

        try {
            Orders orders = ordersService.getOrdersById(orderId);
            return R.ok().data(orders);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @PostMapping("/listOrdersByUserId")
    public R listOrdersByUserId(String userId){
        try {
            List<Orders> ordersList =ordersService.listOrdersByUserId(userId);
            return R.ok().data(ordersList);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    @PostMapping("/paymentOrderById")
    public R paymentOrderById(Integer orderId){
        try {
            int row = ordersService.paymentOrderById(orderId);
            return R.ok().data(row);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
